package com.shop.bank.controller;

import com.shop.bank.pojo.Account;
import com.shop.bank.pojo.Transactionrecord;
import com.shop.bank.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class Acontroller {

    @Autowired
    private AccountService service;

    @RequestMapping("/login")
    public String login(Account account, HttpServletRequest req){
        int loginn = service.loginn(account);
        if(loginn>0){
            req.getSession().setAttribute("card",account.getCardNo());
            return "success";
        }
        return "login";
    }

    @RequestMapping("/money")
    public String money(Model model,String cardNo){
        BigDecimal moneyselect = service.moneyselect(cardNo);
        model.addAttribute("money",moneyselect);
        model.addAttribute("czf",1);
        return "success";
    }

    @RequestMapping("/zz")
    public String zz(Model model,String cardNo,String zzcard,BigDecimal money){
        Map map=new HashMap();
        map.put("cardNo",cardNo);
        map.put("zzcardNo",zzcard);
        map.put("money",money);
        int zz = service.zz(map);
        model.addAttribute("zz",zz);
        return "success";
    }


    @RequestMapping("/jy")
    public String jy(Model model,String cardNo){
        List<Transactionrecord> listall = service.listall(cardNo);
        model.addAttribute("jy",listall);
        return "success";
    }


    @RequestMapping("/up")
    public String up(Model model,String cardNo,String newpwd){
        Map map=new HashMap();
        map.put("cardNo",cardNo);
        map.put("newpwd",newpwd);
        int updatepwd = service.updatepwd(map);
        model.addAttribute("up",updatepwd);
        return "success";
    }






}
